package son.nt.act2;

import son.nt.R;
import son.nt.util.GoogleAnaTool;
import son.nt.util.LogUtil;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.util.Log;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;

public class Act2LifeCycleActivity extends Activity{
	private static final String TAG = "Act2LifeCycleActivity" ;
	private Context mContext =  null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		mContext = this;
		setContentView(R.layout.act2_life_cycle);
		LogUtil.d(mContext, TAG, "oncreate");
		GoogleAnaTool.track("/Act2LifeCycleActivity");
	}
	
	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		LogUtil.d(mContext, TAG, "onStart");
		try {
			PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 1);
			String packageName = info.packageName;
			String versionName = info.versionName;
			
			CookieSyncManager.createInstance(mContext);
			CookieManager mCookieManager = CookieManager.getInstance();
			String domain = "dev.melody.pipli.jp";
			
			String kankyo = "";
			String cookieKey = "NEBIGBOOKPKGINFO";
			String cookieValue = packageName + "|" + versionName + "|" + kankyo;
			String cookies = cookieKey + "=" + cookieValue + "; domain = " + domain;
			LogUtil.v(mContext, TAG, "cookies:" + cookies);
			mCookieManager.setCookie(domain, cookies);
			mCookieManager.setCookie(domain, "sonnt");
			CookieSyncManager.getInstance().sync();
			String getCookie = mCookieManager.getCookie(domain);
			Log.v(TAG, "getCookie:"+getCookie);
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
		super.onStart();
	}
	@Override
	protected void onResume() {
		LogUtil.d(mContext, TAG, "onResume");
		super.onResume();
	}
	@Override
	protected void onRestart() {
		// TODO Auto-generated method stub
		LogUtil.d(mContext, TAG, "onRestart");
		super.onRestart();
	}
	
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		LogUtil.d(mContext, TAG, "onPause");
		super.onPause();
	}
	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		LogUtil.d(mContext, TAG, "onStop");
		super.onStop();
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		LogUtil.d(mContext, TAG, "onDestroy");
		super.onDestroy();
	}
	
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		// TODO Auto-generated method stub
		LogUtil.d(mContext, TAG, "onSaveInstanceState");
		outState.putString(TAG, "sonnt onSaveInstanceState");
		super.onSaveInstanceState(outState);
	}
	@Override
	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		super.onRestoreInstanceState(savedInstanceState);
		LogUtil.d(mContext, TAG, "onRestoreInstanceState");
		String save = savedInstanceState.getString(TAG);
		Log.v(TAG, "String save: " + save);
		
	}
}
